from django import forms
from django.forms import ModelForm, CheckboxSelectMultiple, Textarea, TextInput
from django.forms.widgets import HiddenInput
from django.utils.safestring import mark_safe
from djambe.wiki.models import Page


class CheckboxSelectMultipleInline(forms.CheckboxSelectMultiple):
  def render(self, *args, **kwargs): 
    output = super(CheckboxSelectMultipleInline, self).render(*args,**kwargs) 
    return mark_safe(output.replace(u'<ul>', u'<ul style="list-style:none">').replace(u'<li>', u'<li style="float:left;margin-right:10px">'))


class PageForm(ModelForm):
  new_tag1 = forms.CharField(required=False, max_length=20)
  new_tag2 = forms.CharField(required=False, max_length=20)
  new_tag3 = forms.CharField(required=False, max_length=20)
  tag_text = forms.CharField(required=False, max_length=100, widget=HiddenInput())

  def __init__(self, *args, **kwargs):
    super(PageForm, self).__init__(*args, **kwargs)
    self.fields['tags'].help_text = ''

  class Meta:
    model = Page
    widgets = {
      'title': TextInput(attrs={'size':'50'}),
      'tags': CheckboxSelectMultipleInline(),
      'text': Textarea(attrs={'cols': 80, 'rows': 20}),
    }
